<template>
	<view id="auditDetail" v-show="isauditDetail">
		<!-- <uni-nav-bar color="#000" background-color="#fff" :status-bar="true" left-icon="arrowleft" left-text="审核详情" title="审核详情" @clickLeft="back" /> -->
		<uni-auditingCell
			:detail_type='detail_type'
			:detail='auditData'
			:checkOption='checkOption'
			@eventRules="checkEventRules"
			@back='back'
			@checkGroup="checkGroup"
			@toPopupAgree="toPopupAgree"
			@toPopupNotAgree="toPopupNotAgree"
			:isOrgInfo="isOrgInfo"
			>
			</uni-auditingCell>
	</view>
</template>

<script>
	import uniAuditingCell from '@/components/uni-event/uni-auditingcell.vue';
	import {auditDetail,toAuditEvent} from "@/common/api.js";
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	export default{
		data(){
			return{
				id:"",
				auditData:{},
				detail_type:'',
				typeID:'',
				checkOption:[],  //审核记录
				statusList:[{type:"1",checkStatus:'待审核',status:'isAuditing'},{type:'2',checkStatus:'未通过',status:'isNoAudit'},{type:'3',checkStatus:'已通过',status:'isAudit'}],  //状态
				eventRules:'',
				isauditDetail:false,
				popupData:{},
				groupMsg:'',  //小组信息
				groupmd5:"",
				eventmd5:'',
				showPopup:false,
				isOrgInfo:false
			}
		},
		components:{
			uniAuditingCell,
			uniNavBar
		},
		onLoad(e){
			var _this=this;
			_this.id=e.id;
			// console.log(e.typeid,_this.id)
			_this.detail_type=_this.statusList.filter(function(item,index){
				return item.type==e.typeid
			})[0].status
			_this.typeID=e.typeid;
			uni.showLoading({
			    title: '加载中'
			});
			setTimeout(function(){
					uni.hideLoading();
				_this.isauditDetail=true
			},1500)
			_this.getAuditDetail()
		},
		methods:{
			getAuditDetail(){
				var _this=this;
				// _this.id='671'
				var data={examine_id:_this.id}
				// data=JSON.stringify(data)
				auditDetail(data).then(function(res){
					var e=res.data;
					if(e.errcode==0){
						if(e.event_new){
							_this.auditData=JSON.parse(e.event_new);
						}else{
							_this.auditData=JSON.parse(e.event_old);
						}
						// console.log(_this.auditData)
						_this.auditData['createTime']=e.data[0].create_time?e.data[0].create_time.slice(0,16):"";
						_this.auditData['top_level']=_this.auditData.top_level_name!=null&&_this.auditData.top_level_name!=''?_this.auditData.top_level_name:null;
						_this.auditData['org_name']=e.data[0].org_name;
						if(e.groupmd5){
							_this.groupmd5=e.groupmd5
						}
						if(e.eventmd5){
							_this.eventmd5=e.eventmd5
						}
						try{
						  _this.eventRules = decodeURIComponent(_this.auditData.eventnotice)
						}catch(err){
						  _this.eventRules =_this.auditData.eventnotice;
						}
						if(e.group_new){
							_this.groupMsg=e.group_new
						}else{
							_this.groupMsg=e.group_old
						}
						_this.auditData["signUpCost"]=_this.screenEventCost(JSON.parse(_this.groupMsg)['step1'],JSON.parse(_this.groupMsg)["step2"])
						_this.auditData['address_all']=(_this.auditData.province_name?_this.auditData.province_name:"")+(_this.auditData.city_name?_this.auditData.city_name:"")
																						+(_this.auditData.county_name?_this.auditData.county_name:"")+(_this.auditData.address?_this.auditData.address:"")
						if(e.data){
							_this.checkOption.push({
								org_name:e.data[0].org_name,
								state:e.data[0].state,
								create_time:e.data[0].create_time
							})
						}
						_this.isOrgInfo=true;
					}else if(e.errcode==1000||e.errcode==1001){
							uni.removeStorageSync('token');
							uni.reLaunch({
								url:'/pages/home/welcome'
							})
						}else{
						uni.showToast({
							position: 'center',
							icon: 'none',
							title: e.msg
						});
					}
				})
			},
			//判断是否显示赛事报名费
			screenEventCost(step,newStep){
				var _this=this,cost=null;
				console.log(step,newStep)
				if(step && step.length>0){
				  step.map(function(item,index){
						if(item.cost&&item.cost.length>0){
								return cost
						}else{
							if(newStep){
									return cost="￥"+newStep[0]['cost']
							}
						}
					})
				}
				return cost
			},
			back(){
				var _this=this;
				uni.navigateTo({
					url:'/pages/competitionAudit/event/authorizedEvent?isAudit=false'
				})
			},
			//查看竞赛规程
			checkEventRules(){
				var _this=this;
				if(_this.eventRules==""||_this.eventRules==null){
					uni.showToast({
						position: 'center',
						icon: 'none',
						title: "暂无竞赛规程"
					});
					return;
				}
				uni.navigateTo({
					url:'/pages/competitionAudit/rules/rules?examine_id='+_this.id
				})
			},
			checkGroup(){
				var _this=this;
				if(_this.groupMsg!=''&&_this.groupMsg!=null){
					uni.navigateTo({
						url:'/pages/competitionAudit/signUp/signUpAudit?id='+_this.id+"&type="+_this.typeID
					})
				}else{
					uni.showToast({
						position: 'center',
						icon: 'none',
						title: "暂无报名小组数据"
					});
				}
			},
			toPopupAgree(){
				var _this=this,data={};
				data={
					eventmd5:_this.eventmd5,
					examine_id:_this.id,
					groupmd5:_this.groupmd5,
					state:'2'
				}
				toAuditEvent(data).then(function(res){
					var e=res.data
					if(e.errcode==0){
						_this.detail_type="isAudit";
						_this.typeID='3';
						_this.getAuditDetail();
						_this.refreshPrepage();
					}else if(e.errcode==1000||e.errcode==1001){
							uni.removeStorageSync('token');
							uni.reLaunch({
								url:'/pages/home/welcome'
							})
						}else{
						uni.showModal({
							title: '',
							content: e.msg,
							showCancel:false,
							confirmText:"确认",
							confirmColor:"#2680EB"
						});
					}
				})
			},
			toPopupNotAgree(txtReason){
				var _this=this,data={};
				data={
					examine_id:_this.id,
					remark:txtReason,
					state:'1',
					eventmd5:_this.eventmd5,
					groupmd5:_this.groupmd5,
				}
				toAuditEvent(data).then(function(res){
					var e=res.data
					if(e.errcode==0){
						_this.detail_type="isNoAudit";
						_this.typeID='2';
						_this.getAuditDetail();
						_this.refreshPrepage();
					}else if(e.errcode==1000||e.errcode==1001){
							uni.removeStorageSync('token');
							uni.reLaunch({
								url:'/pages/home/welcome'
							})
						}else{
						uni.showModal({
							title: '',
							content: e.msg,
							showCancel:false,
							confirmText:"确认",
							confirmColor:"#2680EB"
						});
					}
				})
			},
			refreshPrepage(){
				var pages=getCurrentPages();
				var prePages = pages[pages.length - 2];//获取到上一个页面对象
				if (prePages == undefined || prePages == null) return; 
				prePages.onPullDownRefresh();
			},
			toCancel(){
				var _this=this;
				_this.showPopup=false
			}
		}
	}
</script>

<style lang='less' scoped>
	.popupTxt{
		background: #fff;
		width: 300px;
		min-height: 150px;
		padding: 10px;
		flex-wrap: wrap;
		font-size: 14px;
	}
</style>
